package com.tengju.data.infrastructure.repository.clickhouse.ods;

import com.tengju.data.domain.model.clickhouse.OdsBigdataStarIndicatorStatRepository;
import com.tengju.data.domain.model.user.StarIndicator;
import com.tengju.data.domain.model.user.UserIdCode;
import com.tengju.data.infrastructure.persistence.mybatis.dataobject.OdsBigdataStarIndicatorStatDO;
import com.tengju.data.infrastructure.persistence.mybatis.mapper.clickhouse.crm.OdsBigdataStarIndicatorStatMapper;
import com.tengju.data.infrastructure.repository.clickhouse.convert.OdsBigdataStarIndicatorConvert;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

@Repository
public class OdsBigdataStarIndicatorStatRepositoryImpl implements OdsBigdataStarIndicatorStatRepository {

    @Resource
    private OdsBigdataStarIndicatorStatMapper odsBigdataStarIndicatorStatMapper;

    @Override
    public List<StarIndicator> batchQueryByIdCode(List<Long> idCodes) {
        if (CollectionUtils.isEmpty(idCodes)) {
            return Collections.emptyList();
        }
        List<OdsBigdataStarIndicatorStatDO> starIndicatorStatDOList =
                odsBigdataStarIndicatorStatMapper.batchQueryByIdCode(idCodes);

        return starIndicatorStatDOList.stream()
                .map(OdsBigdataStarIndicatorConvert::convertToModel)
                .collect(Collectors.toList());

    }

    @Override
    public List<StarIndicator> batchQueryByIdCodeAndDate(Long idCode,Integer day) {

        List<OdsBigdataStarIndicatorStatDO> starIndicatorStatDOList =
                odsBigdataStarIndicatorStatMapper.batchQueryByIdCodeAndDate(idCode,day);

        return starIndicatorStatDOList.stream()
                .map(OdsBigdataStarIndicatorConvert::convertToModel)
                .collect(Collectors.toList());

    }
}
